#include "rcast_Raycaster.h"

Raycaster::Raycaster ( gen::mapConf			*map_conf const,
					   gen::PlayerPos		*player_pos )
{
	ppos =			player_pos;
	mconf =			map_conf;
	currAngle =		90.0f - (player_pos->FOV >> 1);
}


gen::mapPos Raycaster::CastRay ()
{
	/**
		To cast a ray, one must find its intersection in the "map".
		There are various ways to do this, but after some research,
		a simple trigonometric aproach seems to be the best one for the moment,
		in terms of speed/reliability.

		Another worthy mention, is the DDA, though a thorough collision dectection check,
		of 2D edges with it, requires much more processing power than the current solution.

		The basic catch here, is to intersect first horizontally, and then vertically, because
		a ray can cross a map cell, in both vertical and horizontal edges. The current algorithm
		is based of http://www.permadi.com/tutorial/raycast/rayc7.html.
	*/
	

	/////////////////////////////
	//HORIZONTAL EDGES
	/////////////////////////////

	//determine the closest point, check if the ray is facing down or up, to get the correct edge
	gen::mapCoord first_y = floor((ppos->dir >= 180) ? ((ppos->py / mconf->wallHeight) * mconf->wallHeight) + mconf->wallHeight
													 : ((ppos->py / mconf->wallHeight) * mconf->wallHeight) - 1);

	gen::mapCoord first_x = ppos->px + (ppos->py - first_y) / tan(currAngle);


}
